#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"
#include "std_msgs/msg/int32.hpp"


class TopicSubscribe01:public rclcpp::Node
{
    public:
        TopicSubscribe01(std::string name):Node(name)
        {
            RCLCPP_INFO(this->get_logger(),"在下订阅者%s.者也",name.c_str());
            command_subscribe_=this->create_subscription<std_msgs::msg::Int32>("command_topic",10,std::bind(&TopicSubscribe01::command_callback,this,std::placeholders::_1));
        }
    private:
        // 声明一个订阅者
        rclcpp::Subscription<std_msgs::msg::Int32>::SharedPtr command_subscribe_;
        // 收到话题数据的回调函数
        void command_callback(const std_msgs::msg::Int32::SharedPtr msg){
            int a=0;
            a=msg->data*2;
            RCLCPP_INFO(this->get_logger(),"getting: %d",a);
        }
};

int main(int argc, char **argv){
    rclcpp::init(argc,argv);
    /*创建对应节点的共享指针对象*/
    auto node=std::make_shared<TopicSubscribe01>("topic_subscribe_01");
     /* 运行节点，并检测退出信号*/
    rclcpp::spin(node);
    rclcpp::shutdown();
    return 0;
}